package com.example.testgallery;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	private Gallery gallery;
	private Context context;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		context = MainActivity.this;
		gallery = (Gallery) findViewById(R.id.gallery);
			
		
		List<String> mList = new ArrayList<String>();
		for (int i = 0; i < 10; i++) {
			mList.add("2015-1-"+i);
		}
		

        Gallery g = (Gallery) findViewById(R.id.gallery);

        final MarginLayoutParams mlp = (MarginLayoutParams) gallery.getLayoutParams();
        
        int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
        Toast.makeText(context, screenWidth/2/2+"", 0).show();
        
        mlp.setMargins((-screenWidth/2),0,0,0);
        
        
		final MyAdapter adapter = new MyAdapter(mList, MainActivity.this);
		
		gallery.setAdapter(adapter);
		
		gallery.setSelection(0);
		
		gallery.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				
				adapter.setRest(arg2);
				adapter.notifyDataSetChanged();
				gallery.setLayoutParams(mlp);
			}
		});
		
	}

	private MarginLayoutParams getLayoutParams() {
		// TODO Auto-generated method stub
		return null;
	}
}
